package com.xcms.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class ValiFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        System.out.println("Filter1………………");
        //如果用户没有登录跳转等登录页
        HttpServletRequest request=(HttpServletRequest)req;
        HttpServletResponse response=(HttpServletResponse)resp;
        //获取session
        HttpSession session = request.getSession();
        Object username = session.getAttribute("username");
        String uri = request.getRequestURI();
//        if(username==null && !uri.endsWith("login.jsp")&&!uri.endsWith("login"))//说明没有登录拦截
//        {
//            System.out.println("用户没有登录……");
//            response.sendRedirect("login.jsp");
//        }
//        else
             chain.doFilter(req, resp);//放行
    }

    public void init(FilterConfig config) throws ServletException {

    }

}
